<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%@ include file="../config/config.jsp"%>

<%@ page import="java.io.*,java.util.*"%>

<%@ page import="javax.servlet.*,java.text.*"%>
<%
	SimpleDateFormat ftDate = new SimpleDateFormat("yyyy-MM-dd");
	// 当天
	Date date0 = new Date();
	
	// 一周
	Date date7 = new Date();
	date7.setDate(date7.getDate() - 7);
	
	// 一月
	Date date30 = new Date();
	date30.setDate(date30.getDate() - 30);
	
	String today = ftDate.format(date0);// 当天
	String week = ftDate.format(date7); // 一周
	String month = ftDate.format(date30); //一月
	
	// 用户信息
	List<MsgStatistical> userInfo = (List<MsgStatistical>) request.getAttribute("userInfo");
    int sumUser = 0; // 用户总数
    int dayUser = 0; // 当天注册的用户
    int weekUser = 0; // 一周之内注册的用户
    int monthUser = 0; // 一个月之类注册的用户
	for (int i = 0; i < userInfo.size(); i++) {
		MsgStatistical m = userInfo.get(i);
		String userDate = m.getTime(); // 获取的当前日期
		
		sumUser += Integer.parseInt(m.getCount());
		
		if(userDate.equals(today)){
			dayUser = Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一周前的时间相比较，大于返回1，小于返回-1
		int weekResult = userDate.compareTo(week);
		if(weekResult > 0){
			weekUser += Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一月前的时间相比较，大于返回1，小于返回-1
		int monthResult = userDate.compareTo(month);
		if(monthResult > 0){
			monthUser += Integer.parseInt(m.getCount());
		} 
		 
	}
	
	// 排片信息
	List<MsgStatistical> movieSessionInfo = (List<MsgStatistical>) request.getAttribute("movieSessionInfo");
	int sumSession = 0;
    int daySession = 0;
    int weekSession = 0;
    int monthSession = 0;
	for (int i = 0; i < movieSessionInfo.size(); i++) {
		MsgStatistical m = movieSessionInfo.get(i);
		
		String sessionDate = m.getTime(); // 获取的当前日期
		
		sumSession += Integer.parseInt(m.getCount());
		
		if(sessionDate.equals(today)){
			daySession = Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一周前的时间相比较，大于返回1，小于返回-1
		int weekResult = sessionDate.compareTo(week);
		if(weekResult > 0){
			weekSession += Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一月前的时间相比较，大于返回1，小于返回-1
		int monthResult = sessionDate.compareTo(month);
		if(monthResult > 0){
			monthSession += Integer.parseInt(m.getCount());
		} 
	}
	
	// 收入信息
	List<MsgStatistical> incomeInfo = (List<MsgStatistical>) request.getAttribute("incomeInfo");
	Double sumIncome = 0.00;
	Double dayIncome = 0.00;
	Double weekIncome = 0.00;
	Double monthIncome = 0.00;
	
	List<String> dateArray = new ArrayList<String>();
	List<Double> infoArray = new ArrayList<Double>();
	for (int i = 0; i < incomeInfo.size(); i++) {
		MsgStatistical m = incomeInfo.get(i);
		
		String incomeDate = m.getTime(); // 获取的当前日期
		
		sumIncome += Double.parseDouble(m.getCount());
		
		if(incomeDate.equals(today)){
			dayIncome = Double.parseDouble(m.getCount());
		} 
		
		// 当前时间与一周前的时间相比较，大于返回1，小于返回-1
		int weekResult = incomeDate.compareTo(week);
		if(weekResult > 0){
			weekIncome += Double.parseDouble(m.getCount());
			dateArray.add("'"+incomeDate+"'");
			infoArray.add(Double.parseDouble(m.getCount()));
		} 
		
		// 当前时间与一月前的时间相比较，大于返回1，小于返回-1
		int monthResult = incomeDate.compareTo(month);
		if(monthResult > 0){
			monthIncome += Double.parseDouble(m.getCount());
		} 
	}
	
	// 热映影片票房占比
	List<MsgStatistical> incomeCountInfo = (List<MsgStatistical>) request.getAttribute("incomeCountInfo");
	
	// 影片信息
	List<MsgStatistical> movieInfo = (List<MsgStatistical>) request.getAttribute("movieInfo");
	int sumMovie = 0; // 电影总数
    int dayMovie = 0; // 当天上映电影
    int weekMovie = 0; // 一周上映电影
    int monthMovie = 0; // 一月上映电影
    
	for (int i = 0; i < movieInfo.size(); i++) {
		MsgStatistical m = movieInfo.get(i);
		
		String movieDate = m.getTime(); // 影片上映时间
		
		sumMovie += Integer.parseInt(m.getCount());
		
		if(movieDate.equals(today)){ // 当天
			dayMovie = Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一周前的时间相比较，大于返回1，小于返回-1
		int weekResult = movieDate.compareTo(week);
		if(weekResult > 0){
			weekMovie += Integer.parseInt(m.getCount());
		} 
		
		// 当前时间与一月前的时间相比较，大于返回1，小于返回-1
		int monthResult = movieDate.compareTo(month);
		if(monthResult > 0){
			monthMovie += Integer.parseInt(m.getCount());
		} 
	}
		
%>

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户统计</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="../dist/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="../font-awesome/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="../Ionicons/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
<link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">

<script src="../dist/js/jquery.min.js"></script>
<script src="../dist/js/bootstrap.min.js"></script>
<script src="../dist/js/adminlte1.js"></script>

<script src="<%=basePath %>/js/highcharts/highcharts.js"></script>
<script src="<%=basePath %>/js/highcharts/highcharts-more.js"></script>
<script src="<%=basePath %>/js/highcharts/highcharts-3d.js"></script>
<script src="<%=basePath %>/js/highcharts/modules/exporting.js"></script>
<script src="<%=basePath %>/js/highcharts/modules/series-label.js"></script>
<script src="<%=basePath %>/js/highcharts/modules/oldie.js"></script>
<script src="<%=basePath %>/js/highcharts/modules/funnel.js"></script>
<script src="<%=basePath %>/js/highcharts/highcharts-zh_CN.js"></script>

<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
	<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
	<div class="row">
		<div class="col-lg-3 col-xs-3">
            <!-- small box -->
            <div class="small-box bg-aqua">
           		
                <div class="inner">
                    <small>总用户</small>
                    <h3><%=sumUser %><sup style="font-size: 20px">名</sup></h3>
                    <p style="margin:0px">日: <%=dayUser %></p>
					<p style="margin:0px">周: <%=weekUser %></p>
					<p style="margin:0px">月: <%=monthUser %></p>
                </div>
               
                <div class="icon">
                    <i class="ion ion-person-add"></i>
                </div>
                <a href="#" class="small-box-footer">用户统计 <i class="fa fa-arrow-circle-right"></i></a>
            </div>
        </div>
         <!-- ./col -->
        <div class="col-lg-3 col-xs-3">     
            <!-- small box -->
            <div class="small-box bg-green">
            
                <div class="inner">
                    <small>排片合计</small>
                    <h3><span id="income"><%=sumSession %></span><sup style="font-size: 20px">场</sup></h3>
                    <p style="margin:0px">日: <%=daySession %></p>
					<p style="margin:0px">周: <%=weekSession %></p>
					<p style="margin:0px">月: <%=monthSession %></p>
                </div>
                
                <div class="icon">
                    <i class="ion ion-stats-bars"></i>
                </div>
                <a href="#" class="small-box-footer">排片合计 <i class="fa fa-arrow-circle-right"></i></a>
            </div>
        </div>
         <!-- ./col -->
        <div class="col-lg-3 col-xs-3">
            <!-- small box -->
            <div class="small-box bg-yellow">
            
                <div class="inner">
                    <small>收入统计</small>
                    <h3><span id="collection"><%=sumIncome %></span><sup style="font-size: 20px">元</sup></h3>
                    <p style="margin:0px">日: <%=dayIncome %></p>
					<p style="margin:0px">周: <%=weekIncome %></p>
					<p style="margin:0px">月: <%=monthIncome %></p>
                </div>
				
                <div class="icon">
                    <i class="ion ion-social-yen"></i>
                </div>
                <a href="#" class="small-box-footer">收入统计 <i class="fa fa-arrow-circle-right"></i></a>
            </div>
        </div>
        <!-- ./col -->
        <div class="col-lg-3 col-xs-3">
            <!-- small box -->
            <div class="small-box bg-red">
                <div class="inner">
                    <small>影片统计</small>
                    <h3><span id="spending"><%=sumMovie %></span><sup style="font-size: 20px">部</sup></h3>
                   <p style="margin:0px">日: <%=dayMovie %></p>
					<p style="margin:0px">周: <%=weekMovie %></p>
					<p style="margin:0px">月: <%=monthMovie %></p>
                </div>
				
                <div class="icon">
                    <i class="ion ion-pie-graph"></i>
                </div>
                <a href="#" class="small-box-footer">影片统计 <i class="fa fa-arrow-circle-right"></i></a>
            </div>
        </div>
        <!-- ./col -->
	</div>
	
  	<div id="areascontent">
  		<div class="rows" style="margin-bottom: 0.8%; overflow: hidden;">
            <div style="float: left; width: 65%;border-radius: 4px; background-color: #fff;">
                <div class="panel panel-default">
                    <div class="panel-heading"><i class="fa fa-area-chart fa-lg" style="padding-right: 5px;"></i>近七天收入合计（单位：元）</div>
                    <div class="panel-body">
                        <div id="container" style="width:100%;height:300px"></div>
                    </div>
                </div>
            </div>
            <script>
	         // 近七天收入合计
	        	$('#container').highcharts({
			        chart: {
			            type: 'column'
			        },
			        title: {
			            text: ''
			        },
			        subtitle: {
			            text: '数据来源: amberTimeCinema.com'
			        },
			        xAxis: {
			            categories: <%=dateArray%>,
			            crosshair: true
			        },
			        yAxis: {
			            min: 0,
			            title: {
			                text: '总收入 (元)'
			            }
			        },
			        tooltip: {
			            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
			            pointFormat: '<tr><td style="padding:0">' +
			            '<b>{point.y:.1f}</b> 元</td></tr>',
			            footerFormat: '</table>',
			            shared: true,
			            useHTML: true
			        },
			        plotOptions: {
			            column: {
			                borderWidth: 0
			            }
			        },
			        series: [{
			            name: '收入',
			            data: <%=infoArray%>
			        }]
			    });
            </script>
            
            <!--   饼图 -->
            <div style="float: left; width: 33%;border-radius: 4px;margin-left:10px; background-color: #fff;">
                <div class="panel panel-default">
                    <div class="panel-heading"><i class="fa fa-pie-chart fa-lg" style="padding-right: 5px;"></i>热映影片票房构成</div>
                    <div class="panel-body">
                        <div id="container1" style="width:100%;height:300px"></div>
                    </div>
                </div>
                <script>
	                $('#container1').highcharts({
	                	chart: {
	                        type: 'pie',
	                        options3d: {
	                            enabled: true,
	                            alpha: 45,
	                            beta: 0
	                        }
	                    },
	                    title: {
	                        text: ''
	                    },
	                    tooltip: {
	                        headerFormat: '{series.name}<br>',
	                        pointFormat: '{point.name}: <b>{point.percentage:.1f}%</b>'
	                    },
	                    plotOptions: {
	                        pie: {
	                            allowPointSelect: true,
	                            cursor: 'pointer',
	                            depth: 35,
	                            dataLabels: {
	                                enabled: false
	                            },
	                            showInLegend: true
	                        }
	                    },
	                    series: [{
	                        type: 'pie',
	                        name: '热映影片收入占比',
	                        data: <%=incomeCountInfo%>
	                    }]
	                });
                </script>
            </div>
        </div>
  	</div>

</body>
</html>